package io.awen.modules.sign.controller;

import io.awen.common.utils.PageUtils;
import io.awen.common.utils.R;
import io.awen.modules.sign.entity.SignCarDispatchEntity;
import io.awen.modules.sign.entity.SignTaskEntity;
import io.awen.modules.sign.qo.SignTaskQo;
import io.awen.modules.sign.service.SignTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 收运任务表
 *
 * @author liu.wen
 * @email liu.wen@qq.com
 * @date 2022-08-10 00:47:08
 */
@Api(tags = {"收运任务"})
@RestController
@RequestMapping("sign/signtask")
public class SignTaskController {
    @Autowired
    private SignTaskService signTaskService;

    /**
     * 按条件查询 各收运单位 处理的总收运量
     * @param qo
     * @return
     */
    @PostMapping("/weightTotalGroupByTimeLength")
    public R weightTotalGroupByTimeLength(@RequestBody SignTaskQo qo){
        List<Map<String, Object>> mapList = signTaskService.weightTotalGroupByTimeLength(qo);
        return R.ok().put("list", mapList);
    }

    /**
     * 按条件查询 各收运单位 处理的总收运量
     * @param qo
     * @return
     */
    @PostMapping("/weightTotalGroupByUnit")
    public R weightTotalGroupByUnit(@RequestBody SignTaskQo qo){
        List<Map<String, Object>> mapList = signTaskService.weightTotalGroupByUnit(qo);
        return R.ok().put("list", mapList);
    }

    /**
     * 按条件查询 各容器 处理的总收运量
     * @param qo
     * @return
     */
    @PostMapping("/weightTotalGroupByContainer")
    public R weightTotalGroupByContainer(@RequestBody SignTaskQo qo){
        List<Map<String, Object>> mapList = signTaskService.weightTotalGroupByContainer(qo);
        return R.ok().put("list", mapList);
    }

    /**
     * 按条件查询 各车辆 处理的总收运量
     * @param qo
     * @return
     */
    @PostMapping("/weightTotalGroupByCar") //sign/signtask/weightTotalGroupByCar
    public R weightTotalGroupByCar(@RequestBody SignTaskQo qo){
        List<Map<String, Object>> mapList = signTaskService.weightTotalGroupByCar(qo);
        return R.ok().put("list", mapList);
    }

    /**
     * 按条件查询 各容器 处理的总收运量
     * @param qo
     * @return
     */
    @PostMapping("/weightGroupByCarAndTime")
    public R weightGroupByCarAndTime(@RequestBody SignTaskQo qo){
        List<Map<String, Object>> mapList = signTaskService.weightGroupByCarAndTime(qo);
        return R.ok().put("list", mapList);
    }

    /**
     * 按条件查询 各容器 处理的总收运量
     * @param qo
     * @return
     */
    @PostMapping("/totalByCar")
    public R totalByCar(@RequestBody SignTaskQo qo){
        Map<String, Object> map = signTaskService.totalByCar(qo);
        return R.ok().put("map", map);
    }

    @ApiOperation("手动调度")
    @PostMapping("/manual")
//    @RequiresPermissions("sign:signtask:manual")
    public R manualTask(@RequestBody SignTaskEntity task){
        signTaskService.manualTask(task);
        return R.ok();
    }

    @ApiOperation("司机获取分配给自己的待处理收运任务")
    @PostMapping("/driver/list")
//    @RequiresPermissions("sign:signtask:waitedlist")
    public R driverList(@RequestBody SignTaskQo qo){
        PageUtils page =  signTaskService.driverList(qo);
        return R.ok().put("page", page);
    }


    @PostMapping("/queryPageWeightTotalGroupByCar") //sign/signtask/weightTotalGroupByCar
    public R queryPageWeightTotalGroupByCar(@RequestBody SignTaskQo qo){
        PageUtils pageUtils = signTaskService.queryPageWeightTotalGroupByCar(qo);
        return R.ok().put("page", pageUtils);
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("sign:signtask:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = signTaskService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @RequestMapping("/listByQo")
//    @RequiresPermissions("sign:signcardispatch:list")
    public R listByQo(@RequestBody SignTaskQo qo){
        PageUtils page = signTaskService.listByQo(qo);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("sign:signtask:info")
    public R info(@PathVariable("id") Long id){
		SignTaskEntity signTask = signTaskService.getById(id);

        return R.ok().put("signTask", signTask);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("sign:signtask:save")
    public R save(@RequestBody SignTaskEntity signTask){
		signTaskService.save(signTask);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("sign:signtask:update")
    public R update(@RequestBody SignTaskEntity signTask){
		signTaskService.updateById(signTask);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("sign:signtask:delete")
    public R delete(@RequestBody Long[] ids){
		signTaskService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
